const fs = require("fs")
const esprima = require("esprima")
const estraverse = require("estraverse")
const escodegen = require("escodegen")
const iconv = require("iconv-lite")
const base_ast = require("../../tools/es_ast_tool");
const akamai_base = require("../common/akamai_base")



var content = fs.readFileSync("./case1.js",{encoding:"binary"});
var buf = new Buffer.from(content, "binary");
var code = iconv.decode(buf, "utf-8");
var ast = esprima.parse(code);


function deal_switch_case(dis, file){
    var save_file = file.replace(".js","_1.js")
    var content = fs.readFileSync(file,{encoding:"binary"});
    var buf = new Buffer.from(content, "binary");
    var code = iconv.decode(buf, "utf-8");
    var ast = esprima.parse(code);

    var sort_values = base_ast.switchcase_tool(ast, dis);
    var sorted_values = akamai_base.getadjacencyList(sort_values);
    akamai_base.resort_switchcase_tool2(ast,dis, sorted_values, save_file);
}

// deal_switch_case("t3", "./case1.js")
deal_switch_case("Kpg", "./case2.js")
